$(function(){
    //加载角色权限;对应的id
    var zNodes;
    // 控制ztree的状态,系统管理的ztree//87行代码;
    var setting = {
        check: {
            enable: true,
            chkboxType: {"Y" : "ps", "N" : "ps"}
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };
    //从后台获取ztree中的东西;
    $.ajax({
        type:'get',
        headers: {"Accept-CMS-Token":token},
        url:permissionlist,
        async:false,//这一步在这个页面当中是关键部分;千万不能去了;
        cache:false,
        data:{},
        dataType:'json',
        success:function(result){
            zNodes=result.value;
            console.log('加载角色权限接口请求成功!!!!');
            // console.log(zNodes)
        },
        error:function (){
            console.log('加载角色权限图片列表获取失败!!');
        }
    });
    var code;
    // 有关ztree
    function setCheck()
    {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
            py = $("#py").attr("checked")? "p":"",
            sy = $("#sy").attr("checked")? "s":"",
            pn = $("#pn").attr("checked")? "p":"",
            sn = $("#sn").attr("checked")? "s":"",
            type = { "Y":'ps', "N":'ps'};
        zTree.setting.check.chkboxType = type;
        showCode(setting.check.chkboxType = { "Y" : "ps", "N" : "ps" });
    };
    function showCode(str){
        if (!code) code = $("#code");
        code.empty();
        code.append("<li>"+str+"</li>");
    };
    $(document).ready(function(){
        // ztree要整合的一些东西;初始化页面
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        setCheck();
        $("#py").bind("change", setCheck);
        $("#sy").bind("change", setCheck);
        $("#pn").bind("change", setCheck);
        $("#sn").bind("change", setCheck);
    });




})